

/*
cblas_ccopy
Copies a vector to another vector (single-precision complex).
https://developer.apple.com/documentation/accelerate/1513152-cblas_ccopy?changes=la__3__8_3&language=objc

Parameters
N
Number of elements in the vectors.

X
Source vector X.

incX
Stride within X. For example, if incX is 7, every 7th element is used.

Y
Destination vector Y.

incY
Stride within Y. For example, if incY is 7, every 7th element is used.

Discussion
On return, the contents of vector Y are replaced with the result. The value computed is (alpha * X[i]) + Y[i].
 */

use crate::cblash_h;
use common::complex::complex::Complex;

 
pub fn cblas_ccopy(
    N: i32,
    X: &Vec<Complex>,
    incX: i32,
    Y: &mut Vec<Complex>,
    incY: i32,
) {
    // #include "source_copy_c.h"
    if N < 1 {
        panic!("cblas_ccopy: N < 1");
    }

    let len_x = X.len();
    let len_y = Y.len();

    let ix = cblash_h::offset(N as usize, incX);
    let iy = cblash_h::offset(N as usize, incY);

    if len_x < ix.len_mustbe {
        panic!("cblas_caxpy: X 长度 {len_x} < 应该的长度 {}", ix.len_mustbe);
    }
    if len_y < iy.len_mustbe {
        panic!("cblas_caxpy: Y 长度 {len_y} < 应该的长度 {}", iy.len_mustbe);
    }

    for idx in 0..ix.indices.len() {
        let item_x = X.get(ix.indices[idx]).expect("Unreachable");
        let item_y = Y.get_mut(iy.indices[idx]).expect("Unreachable");

        item_y.real = item_x.real;
        item_y.imag += item_x.imag;
    }
}
